package com.yunjian.admin.controller;

import com.github.pagehelper.PageInfo;
import com.yunjian.admin.vo.WebResult;
import com.yunjian.core.busi.model.Store;
import com.yunjian.core.busi.model.StoreExample;
import com.yunjian.core.busi.service.StoreService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * @author tsh721@126.com
 */
@Controller
@RequestMapping("/store")
public class StoreController {

    private static DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    private static final Logger logger = LoggerFactory.getLogger(StoreController.class);

    @Autowired
    private StoreService storeService;

    @ResponseBody
    @RequestMapping("/list")
    @ApiOperation(value = "门店列表")
    @RequiresPermissions("store:list")
    public WebResult<PageInfo<Store>> list(
            @ApiParam(value = "页面Size") @RequestParam(required = true) int rows,
            @ApiParam(value = "页") @RequestParam(required = true) int page,
            @ApiParam(value = "所在城市") String city) {
        WebResult<PageInfo<Store>> ret = new WebResult<>();
        StoreExample example = new StoreExample();
        StoreExample.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotBlank(city)) {
            criteria.andCityEqualTo(city);
        }
        ret.setAttach(storeService.selectPagedByExample(page, rows, example));
        return ret.setCoder(WebResult.Coder.SUCCESS);
    }

}
